<include file="../Public/header" />
<link href="{:APPS_URL}/w3g/_static/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
  body{background-color: #fff;}
</style>
<div id="content">
    <div id="weiba" data-title="修改头像" class="panel" data-selected="true"  data-menu="msgmenu" style="padding:0;">
        <header>
            <div id="header-buttons">
                <a href="javascript:history.go(-1);">
                    <div id="back" class="header-menu-link" data-back="false">
                    </div>
                </a>
            </div>
            <h1 class="hasback">
                修改头像
            </h1>
        </header>
    <div class="set-item" id="">
        <form onsubmit="return check()" id="saveAvatar"  action="{:U('w3g/Setting/doSaveAvatar', array('step'=>'upload'))}" method="post" enctype="multipart/form-data">
         <div class="form-set">
            <dl class="arbg noborder" onclick="">
                <dd style="position:relative;">
                <php>if($fullpicurl == '') {</php>
                <img width="200" src="{$user.avatar_middle}">
                <php>}else{</php>
                <img width="200" src="{$fullpicurl}">
                <php>}</php>
                <input type="file" name="Filedata" id="imageInput" accept="image/gif,image/jpeg,image/jpg,image/png" style="opacity:0;position:absolute;left:0;right:0;top:0;bottom:0;width:100%;height:100%;" onchange="_submit()" />
                </dd>
            </dl>
         </div>
        </form>
        <php>if($fullpicurl != '') {</php>
        <form onsubmit="return isAllowCut();" id="cutAvatar"  action="{:U('w3g/Setting/doCutAvatar', array('step'=>'save'))}" method="post">
        <input id="avatar_picurl" type="hidden" name="picurl" value="{$picurl}">
        <input id="avatar_picwidth" type="hidden" name="picwidth" value="{$picwidth}">
        <input id="avatar_fullpicurl" type="hidden" name="fullpicurl" value="{$fullpicurl}">
        <input id="avatar_x1" type="hidden" name="x1" value="0">
        <input id="avatar_y1" type="hidden" name="y1" value="0">
        <input id="avatar_x2" type="hidden" name="x2" value="{$picwidth}">
        <input id="avatar_y2" type="hidden" name="y2" value="{$picwidth}">
        <input id="avatar_w" type="hidden" name="w" value="{$picwidth}">
        <input id="avatar_h" type="hidden" name="h" value="{$picwidth}">
         <div class="setBtn"><button class="btn-big" style="border:0;" type="submit">保存</button></div>
        </form>
        <php>}</php>
    </div>
</div>
<script type="text/javascript">
    var msg = '{$msg}';
    var step = '{$step}';
    var status = '{$status}';
    var picwidth = '{$picwidth}';
    var picheight = '{$picheight}';
    var picurl = '{$picurl}';
    var fullpicurl = '{$fullpicurl}';
    var isCut = false;
    window.onload = function(){
        if(step != '' && ~~status == 0){
            $.ui.showMask(msg,true);
        }
        if(step != '' && ~~status == 1){
            $("#menu dt img").attr("src", fullpicurl);
            if(picwidth < picheight){
                picwidth = Math.round(picwidth/(picwidth/300));
                $('#avatar_x2').val(picwidth);
                $('#avatar_y2').val(picwidth);
                $('#avatar_w').val(picwidth);
                $('#avatar_h').val(picwidth);
            }else{
                picheight = Math.round(picheight/(picheight/300));
                $('#avatar_x2').val(picheight);
                $('#avatar_y2').val(picheight);
                $('#avatar_w').val(picheight);
                $('#avatar_h').val(picheight);
            }
            isCut = true;
        }
    };
    function isAllowCut(){
        return isCut;
    }
    function check(){
        var img = $('#imageInput').val();
        var regExp = /\.(jpg|gif|png)$/i;
        if(!regExp.test(img)){
            $.ui.showMask("请选择jpg/png/gif类型图片",true);
            return false;
        }
        return true;
    }
    var _submit = function(){
        // $('#saveAvatar').submit();
        document.getElementById('saveAvatar').submit();
    }
</script>
<include file="../Public/footer" />